package com.doumuxie.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author doumuxie https://gitee.com/doumuxie/
 * @version 1.0
 * @date 2020/10/12 21:51
 * @description
 **/
public class DateUtil {

    public static String FORMAT_YYYY_MM_DD = "yyyy-MM-dd";

    public static String FORMAT_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

    /**
     * 获取昨天日期
     *
     * @return 昨天日期
     */
    public static String getYesterday() {
        return getYesterday(FORMAT_YYYY_MM_DD);
    }

    public static String getYesterday(String formatStr) {
        Date today = new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatStr);
        return simpleDateFormat.format(today);
    }

    public static String getDate(Date date) {
        return getDate(date, FORMAT_YYYY_MM_DD);
    }

    /**
     * 获取日期时间
     *
     * @param date date
     * @return 日期时间
     */
    public static String getDateTime(Date date) {
        return getDate(date, FORMAT_YYYY_MM_DD_HH_MM_SS);
    }

    public static String getDate(Date date, String formatStr) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatStr);
        return simpleDateFormat.format(date);
    }

    public static String getToday() {
        return getYesterday(FORMAT_YYYY_MM_DD);
    }

    public static String getToday(String formatStr) {
        Date today = new Date(System.currentTimeMillis());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatStr);
        return simpleDateFormat.format(today);
    }

}
